

import java.awt.Color;
import java.awt.Font; 

import javax.swing.plaf.FontUIResource; 

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.UIManager;

/**
 * Contains all the popup windows needed with the exception of the one for the TicketGrid class
 * (located in the TicketGrid class).  runReservation, runManageEmployees, and runManageMenu methods
 * have been written to continuously loop should any input not be parsed and retains the information
 * previously entered.
 * @author Mike Jones
 * @version 1.0
 */
public class PopUp {

	private static String numTyped="";
	private static JPanel numbersPanel;
	private static JTextField amount;
	private static String idTyped="";
	private static JButton numButton;
	
	
	/**
	 * Obtains the number of customers - if submit is selected with no input the user is asked to
	 * re-enter.  Same if the clear button is selected.
	 * @return the number of customers
	 */
	public static int getNumCustomers(){
		
		//if table already has an order started
		//database code here
		//return the number of customers
		
		//else do this
		int yn = runSeatCount();
		//If 1, then clear the text field and ask again
		//If 0 but no number was entered, ask again
		while (((yn==0 && amount.getText().isEmpty()==true))|| yn==1 || (yn==0 && amount.getText().equals("0"))){
			if(yn==1 || (yn==0 && amount.getText().equals("0"))){
				amount.setText("");
				idTyped="";
			}
			yn = runSeatCount();
		}
		
		if(yn==-1 || yn==2){//user cancels
			amount.setText("");
			idTyped="";
			return -1;
		}
			idTyped = "";
			return Integer.parseInt(amount.getText());

	}//End of getNumCustomers method
	
	/**
	 * Used to obtain the number of tickets to be displayed
	 * @return an integer 0 (Submit) or 1 (Clear)
	 */
	public static int runSeatCount(){
		Object[] choices = {"Submit", "Clear", "Cancel"};
		Object defaultChoice = choices[0];

		JPanel seatPanel = new JPanel();
		seatPanel.setLayout(new FlowLayout());
		
		JLabel tickets = new JLabel("# of Tickets");
		tickets.setFont(new Font("Arial", Font.PLAIN, 30));
		seatPanel.add(tickets);
		amount = new JTextField(6);
		amount.setEditable(false);
		amount.setFont(new Font("Arial", Font.PLAIN, 30));
		amount.setBackground(Color.WHITE);
		seatPanel.add(amount);
		numbersPanel = new JPanel(new GridLayout(4,3));
		for(int i = 1; i < 11; i++){
			if (i==10){
				i=0;
			}
			createNumButton(i);
			if (i==0){
				i=10;
			}
		}
		seatPanel.add(numbersPanel);
		
		//Increase size of the buttons
		UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("ARIAL",Font.PLAIN,40))); 
		//Increase size of the textfont
		UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("ARIAL",Font.PLAIN,40)));
	

		int i = JOptionPane.showOptionDialog(
				null,
				seatPanel,
				null,
				JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.PLAIN_MESSAGE,
				null,
				choices,
				defaultChoice);		
		
		return i;
	}//End runSeatCount method
	
	/**
	 * Creates the actual individual buttons for the number pad
	 * @param a - a number 0-9
	 */
	private static void createNumButton(int a){
		String num = Integer.toString(a);
		numButton = new JButton("    "+num+"    ");
		numButton.setFont(new Font("Arial", Font.PLAIN, 80));
		numButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				idTyped+=a;
				amount.setText(idTyped);
			}
		});
		
		numbersPanel.add(numButton);
	}//End createNumButton method


	/**
	 * Allows a Server to claim cash tips and clock out
	 * @return - Returns the amount of cash tips claimed or an empty string if user cancels
	 */
	public static String runServerClockOut(){
		Object[] choices = {"Clock Out", "Clear", "Cancel"};
		Object defaultChoice = choices[0];

		JPanel tipPanel = new JPanel();
		JLabel tipsLabel = new JLabel("Cash Tips:");
		tipsLabel.setFont(new Font("Arial", Font.PLAIN, 40));
		tipPanel.add(tipsLabel);
		amount = new JTextField(10);
		amount.setFont(new Font("Arial", Font.PLAIN, 40));
		amount.setEditable(false);
		amount.setBackground(Color.WHITE);
		tipPanel.add(amount);

		numbersPanel = new JPanel(new GridLayout(4,3));
		for(int i = 1; i < 12; i++){
			String j = i+"";
			if (i==10){
				j="0";
			}
			if (i==11){
				j=".";
			}
			createNumButton(j);
		}
		tipPanel.add(numbersPanel);
		
		font();

		int i = JOptionPane.showOptionDialog(
				null,
				tipPanel,
				null,
				JOptionPane.YES_NO_CANCEL_OPTION,
				JOptionPane.PLAIN_MESSAGE,
				null,
				choices,
				defaultChoice);

		// if user selects Clock Out and cash tips are being claimed, confirm amount entered in is a valid dollar amount
		if (i == 0){
			if (amount.getText().isEmpty()==false){
				String dAmount = amount.getText();
				String cTips = parseDollar(dAmount); //parse the dollar amount
				if (cTips.equals("-1") == true){
					JOptionPane.showMessageDialog(tipPanel, "$"+dAmount + " is an invalid amount.  Clock Out canceled"); 
					amount.setText("");
					numTyped = "";
					return "0.00";
				}
				else{
					numTyped = "";
					return cTips;
				}
			}
			else {
				numTyped = "";
				return "0.00"; //if user does not claim cash tips
			}
		}
		else if (i == -1 || i == 2){
			amount.setText("");
			numTyped = "";
			return "";//if user selects Cancel
		}
		else{
			numTyped = "";
			return "CLEAR";
		}
	}//End runServerClockOut method

	/**
	 * Creates the actual individual buttons for the number pad
	 * @param a - a String 0-9 or .
	 */
	private static void createNumButton(String a){
		JButton numButton = new JButton("    "+a+"    ");
		numButton.setFont(new Font("Arial", Font.PLAIN, 80));
		numButton.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				numTyped+=a;
				amount.setText(numTyped);
			}
		});

		numbersPanel.add(numButton);
	}//End createNumButton method

	/**
	 * Verifies that the dollar amount entered in is a valid double format (precision loss beyond two decimals is acceptable)
	 * @param dAmount - the dollar amount(String)
	 * @return cash if the parse is successful or -1 if not (String)
	 */
	private static String parseDollar(String dAmount){
		//Removes all characters that are not a digit or period
		//Replaces with an empty value
		String charRemove = dAmount.replaceAll("[^\\d.]", "");

		try{
			DecimalFormat df = new DecimalFormat("#.00");
			String cash = df.format(Double.parseDouble(charRemove));
			return cash;
		}
		catch(Exception e){
			return "-1";
		}//End try/catch block

	}//End parseDollar method



	/**
	 * Used for a Hostess/Manager to clock out
	 * Returns an integer 0 (Clock Out), 1 (Cancel)
	 */
	public static int runClockOut(){
		Object[] choices = {"Clock Out", "Cancel"};
		Object defaultChoice = choices[0];
		
		font();
		int i = JOptionPane.showOptionDialog(
				null, "Do you want to clock out?",
				null,
				JOptionPane.YES_NO_OPTION,
				JOptionPane.PLAIN_MESSAGE,
				null,
				choices,
				defaultChoice);
		
		if (i==-1){
			i = 1;//clicking X is cancelling
		}
		
		return i;
	}//End runClockOut method


	/**
	 * Allows a Hostess to enter in or modify information for a reservation or waitlist
	 * @param - a is an ArrayList - if not null then the fields with be set with the information
	 * used before a parsing error occurred
	 * @return - an ArrayList containing the results of the input
	 */
	public static ArrayList<String> runReservation(ArrayList<String> a){
		Object[] choices = {"Submit", "Cancel"};
		Object defaultChoice = choices[0];

		JPanel reserve = new JPanel(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		JPanel notesPanel = new JPanel();
		notesPanel.setLayout(new BoxLayout(notesPanel, BoxLayout.Y_AXIS));

		//First field for Date
		gbc.gridx = 0;
		gbc.gridy = 0;
		JLabel d = new JLabel("Date");
		d.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(d, gbc);
		JTextField date = new JTextField(10);
		gbc.gridx = 0;
		gbc.gridy = 1;
		date.setText(a.get(0));
		date.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(date, gbc);

		//Second field for Time
		gbc.gridx = 1;
		gbc.gridy = 0;
		JLabel t = new JLabel("Time");
		t.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(t, gbc);
		JTextField time = new JTextField(10);
		gbc.gridx = 1;
		gbc.gridy = 1;
		time.setText(a.get(1));
		time.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(time, gbc);

		//Third field for # in Party
		gbc.gridx = 2;
		gbc.gridy = 0;
		JLabel numParty = new JLabel("# in Party");
		numParty.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(numParty, gbc);
		JTextField partyNum = new JTextField(5);
		gbc.gridx = 2;
		gbc.gridy = 1;
		partyNum.setText(a.get(2));
		partyNum.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(partyNum, gbc);

		//Fourth field for Name
		gbc.gridx = 3;
		gbc.gridy = 0;
		JLabel cName = new JLabel("Name");
		cName.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(cName, gbc);
		JTextField name = new JTextField(15);
		gbc.gridx = 3;
		gbc.gridy = 1;
		name.setText(a.get(3));
		name.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(name, gbc);

		//Fifth field for Phone Number
		gbc.gridx = 4;
		gbc.gridy = 0;
		JLabel pn = new JLabel("Phone Number");
		pn.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(pn, gbc);
		JTextField phoneNum = new JTextField(15);
		gbc.gridx = 4;
		gbc.gridy = 1;
		phoneNum.setText(a.get(4));
		phoneNum.setFont(new Font("Arial", Font.PLAIN, 25));
		reserve.add(phoneNum, gbc);

		//Sixth field for Notes
		JLabel n = new JLabel("Notes");
		n.setFont(new Font("Arial", Font.PLAIN, 25));
		notesPanel.add(n);
		JTextArea notes = new JTextArea(5,30);
		notes.setText(a.get(5));
		notes.setFont(new Font("Arial", Font.PLAIN, 25));
		notes.setLineWrap(true);
		notes.setWrapStyleWord(true);
		notes.setSize(5, 30);
		notes.setPreferredSize(notes.getPreferredSize());
		notesPanel.add(notes);
		gbc.gridx = 0;
		gbc.gridy = 2;
		gbc.gridwidth = 4;
		reserve.add(notesPanel, gbc);

		//Clear 'a' arraylist if it contained data
		a.clear();
		
		font();
		int i = JOptionPane.showOptionDialog(
				null,
				reserve,
				null,
				JOptionPane.YES_NO_OPTION,
				JOptionPane.PLAIN_MESSAGE,
				null,
				choices,
				defaultChoice);

		//Place the results from the inputs into an arraylist
		ArrayList<String> results = new ArrayList<String>();
		results.add(date.getText());
		results.add(time.getText());
		results.add(partyNum.getText());
		results.add(name.getText());
		results.add(phoneNum.getText());
		results.add(notes.getText());
		//Parse results is submit is selected otherwise clear and cancel
		if (i==0){
			if(parseReservations(results) == true){
				return results;
			}
			else{
				results.add("ERROR");
				return results;
			}
		}
		else {
			results.clear();
			return null;
		}

	}//End runReservation method

	/**
	 * Parses the input taken from the Reservation/Waitlist fields
	 * @param data - the arraylist of the date from the runReservation method
	 * @return - boolean of whether the data parses or not
	 */
	private static boolean parseReservations(ArrayList<String> data){

		if(parseDate(data.get(0)) == false){
			return false;
		}

		if(parseTime(data.get(1)) == false){
			return false;
		}

		if(parseDigit(data.get(2)) == false){
			return false;
		}

		if(parsePhoneNumber(data.get(4)) == false){
			return false;
		}

		return true;
	}//End of parseReservations method

	/**
	 * Verifies a date has been entered in a mm/dd/yyyy or mm-dd-yyyy format
	 * @param d - String value holding the date variable
	 * @return - boolean of whether the date parses or not
	 */
	private static boolean parseDate(String d){
		String date = d;
		String dateTest = date.replaceAll("[^\\d]", "");
		Calendar now = Calendar.getInstance();
		int year = now.get(Calendar.YEAR);
		
		font();
		//All dates must be at least 8 characters without separators
		if (dateTest.length() != 8){
			JOptionPane.showMessageDialog(null, "An invalid date was entered: "+date +". \nDate must be entered as a MM-DD-YYYY or MM/DD/YYYY format.", null, JOptionPane.PLAIN_MESSAGE, null);
			return false;
		}
		//Check if the month falls between 1 and 12
		if (Integer.parseInt(dateTest.substring(0,2)) < 1 || Integer.parseInt(dateTest.substring(0,2)) > 12){
			JOptionPane.showMessageDialog(null, "An invalid date was entered: "+date +". \nDate must be entered as a MM-DD-YYYY or MM/DD/YYYY format.", null, JOptionPane.PLAIN_MESSAGE, null);
			return false;
		}
		//Check if the days were entered correctly
		else if (Integer.parseInt(dateTest.substring(2,4)) < 1 || Integer.parseInt(dateTest.substring(2,4)) > 31){
			JOptionPane.showMessageDialog(null, "An invalid date was entered: "+date +". \nDate must be entered as a MM-DD-YYYY or MM/DD/YYYY format.", null, JOptionPane.PLAIN_MESSAGE, null);
			return false;
		}
		//Check if year was entered correctly (can not be before current year or over 100 years pass current year)
		else if (Integer.parseInt(dateTest.substring(4)) < year || Integer.parseInt(dateTest.substring(4)) > year+100){
			JOptionPane.showMessageDialog(null, "An invalid date was entered: "+date +". \nDate must be entered as a MM-DD-YYYY or MM/DD/YYYY format.", null, JOptionPane.PLAIN_MESSAGE, null);
			return false;
		}
		else{
			return true;
		}
	}//End parseDate method

	/**
	 * Verifies that a time has been entered in a HH:MM format
	 * @param t - String value holding the time variable
	 * @return - boolean of whether the date parses or not
	 */
	private static boolean parseTime(String t){
		String time = t;
		
		font();
		//All times must have a length less than 5
		if (time.length() > 5){
			JOptionPane.showMessageDialog(null, "An invalid time was entered: "+time, null, JOptionPane.PLAIN_MESSAGE, null);
			return false;
		}

		try{
			int hour = Integer.parseInt(time.substring(0,time.indexOf(":",0)));
			int min =  Integer.parseInt(time.substring(time.indexOf(":",0)+1));
		}//End try
		catch(Exception e){
			JOptionPane.showMessageDialog(null, "An invalid time was entered: "+time, null, JOptionPane.PLAIN_MESSAGE, null);
			return false;
		}//End catch
		return true;
	}//End of parseTime method

	/**
	 * Verifies that a number is not negative and is a valid number
	 * @param digit - String of the number to be parsed
	 * @return - boolean of whether the number parses or not
	 */
	private static boolean parseDigit(String digit){
		try{
			int d = Integer.parseInt(digit);
			if(d < 0){
				return false;
			}
		}//End try
		catch(Exception e){
			font();
			JOptionPane.showMessageDialog(null, "An invalid amount was entered: "+digit, null, JOptionPane.PLAIN_MESSAGE, null);
			return false;
		}//End catch
		return true;
	}//End of parseDigit method

	/**
	 * Verifies that a phone number follows a XXX-XXX-XXXX format and is all digits
	 * @param pn - string of the phone number
	 * @return - boolean of whether the phone number parses or not
	 */
	private static boolean parsePhoneNumber(String pn){

			String phone = pn.replace("-", "");
			
			font();
			
			if(phone.length() != 10){
				JOptionPane.showMessageDialog(null, "An invalid amount was entered: "+pn+"\nPhone numbers must be entered in a XXX-XXX-XXXX format", null, JOptionPane.PLAIN_MESSAGE, null);
				return false;
			}

			for(int i = 0; i < phone.length(); i++){
				if(Character.isDigit(phone.charAt(i)) == false){
					JOptionPane.showMessageDialog(null, "An invalid amount was entered: "+pn+"\nPhone numbers must be entered in a XXX-XXX-XXXX format", null, JOptionPane.PLAIN_MESSAGE, null);
					return false;
				}
			}

		return true;
	}//End parsePhoneNumbers method

	/**
	 * Allows a Manager to add or modify an employee to the database
	 * @param - a is an ArrayList - if not null then the fields with be set with the information
	 * used before a parsing error occurred
	 * @return - an ArrayList containing the results of the input
	 */
	public static ArrayList<String> runManageEmployee(ArrayList<String> a){
		Object[] choices = {"Submit", "Cancel"};
		Object defaultChoice = choices[0];

		JPanel employee = new JPanel(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		JPanel notesPanel = new JPanel();
		notesPanel.setLayout(new BoxLayout(notesPanel, BoxLayout.Y_AXIS));

		//First field of Name
		gbc.gridx = 0;
		gbc.gridy = 0;
		JLabel nLabel = new JLabel("Name");
		nLabel.setFont(new Font("Arial", Font.PLAIN, 25));
		employee.add(nLabel, gbc);
		JTextField name = new JTextField(15);
		gbc.gridx = 0;
		gbc.gridy = 1;
		name.setText(a.get(0));
		name.setFont(new Font("Arial", Font.PLAIN, 25));
		employee.add(name, gbc);

		//Second field of Password
		gbc.gridx = 1;
		gbc.gridy = 0;
		JLabel pWord = new JLabel("Password");
		pWord.setFont(new Font("Arial", Font.PLAIN, 25));
		employee.add(pWord, gbc);
		JTextField passWord = new JTextField(10);
		gbc.gridx = 1;
		gbc.gridy = 1;
		passWord.setText(a.get(1));
		passWord.setFont(new Font("Arial", Font.PLAIN, 25));
		employee.add(passWord, gbc);

		//Third field of Hours/Week
		gbc.gridx = 2;
		gbc.gridy = 0;
		JLabel hw = new JLabel("Hours/Week");
		hw.setFont(new Font("Arial", Font.PLAIN, 25));
		employee.add(hw, gbc);
		JTextField hours = new JTextField(15);
		gbc.gridx = 2;
		gbc.gridy = 1;
		hours.setText(a.get(2));
		hours.setFont(new Font("Arial", Font.PLAIN, 25));
		employee.add(hours, gbc);

		//Fourth field of Job Title
		gbc.gridx = 3;
		gbc.gridy = 0;
		JLabel jt = new JLabel("Job Title");
		jt.setFont(new Font("Arial", Font.PLAIN, 25));
		employee.add(jt, gbc);
		String[] titles = {"Server", "Hostess", "Manager"};
		JComboBox jobTitle = new JComboBox(titles);
		gbc.gridx = 3;
		gbc.gridy = 1;
		//If an error was made on input, display what was previously selected
		if(a.get(0) != null){
			for(int i = 0; i < titles.length; i++){
				if (a.get(3).equals(titles[i].toString())){
					jobTitle.setSelectedIndex(i);
				}
			}
		}
		else{
			jobTitle.setSelectedIndex(0); //otherwise display the first option
		}
		jobTitle.setFont(new Font("Arial", Font.PLAIN, 25));
		jobTitle.setBackground(Color.WHITE);
		employee.add(jobTitle, gbc);

		//Fifth field of notes
		JLabel n = new JLabel("Notes");
		n.setFont(new Font("Arial", Font.PLAIN, 25));
		notesPanel.add(n);
		JTextArea notes = new JTextArea(5,30);
		notes.setLineWrap(true);
		notes.setWrapStyleWord(true);
		notes.setSize(5, 30);
		notes.setPreferredSize(notes.getPreferredSize());
		notes.setText(a.get(4));
		notes.setFont(new Font("Arial", Font.PLAIN, 25));
		notesPanel.add(notes);
		gbc.gridx = 0;
		gbc.gridy = 2;
		gbc.gridwidth = 4;
		employee.add(notesPanel, gbc);

		//Clear 'a' arraylist if it contained data
		a.clear();
		
		font();

		int i = JOptionPane.showOptionDialog(
				null,
				employee,
				null,
				JOptionPane.YES_NO_OPTION,
				JOptionPane.PLAIN_MESSAGE,
				null,
				choices,
				defaultChoice);

		//Place the results from the inputs into an arraylist
		ArrayList<String> results = new ArrayList<String>();
		results.add(name.getText());
		results.add(passWord.getText());
		results.add(hours.getText());
		results.add(jobTitle.getSelectedItem().toString());
		results.add(notes.getText());

		//Parse results is submit is selected otherwise clear and cancel
		if (i==0){
			if(parseManageEmployee(results) == true){
				return results;
			}
			else{
				results.add("ERROR");
				return results;
			}
		}
		else {
			results.clear();
			return null;
		}
	}//End runManageEmployee method

	/**
	 * Parses the input taken from the ManageEmployee fields
	 * @param data - the arraylist of the date from the runManageEmployee method
	 * @return - boolean of whether the data parses or not
	 */
	private static boolean parseManageEmployee(ArrayList<String> data){

		if(parseDigit(data.get(2)) == false){
			return false;
		}

		return true;
	}//End of parseManageEmployee method

	/**
	 * Allows a Manager to add or modify a Menu Item
	 * Returns an integer 0 (Submit), 1 (Cancel)
	 * @return 
	 */
	public static ArrayList<String> runMenuItem(ArrayList<String> a){
		Object[] choices = {"Submit", "Cancel"};
		Object defaultChoice = choices[0];

		JPanel menu = new JPanel(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();

		//First field of Name
		gbc.gridx = 0;
		gbc.gridy = 0;
		JLabel iName = new JLabel("Name");
		iName.setFont(new Font("Arial", Font.PLAIN, 25));
		menu.add(iName, gbc);
		JTextField name = new JTextField(15);
		gbc.gridx = 0;
		gbc.gridy = 1;
		name.setText(a.get(0));
		name.setFont(new Font("Arial", Font.PLAIN, 25));
		menu.add(name, gbc);

		//Second field of Item Cost
		gbc.gridx = 1;
		gbc.gridy = 0;
		JLabel iCost = new JLabel("Item Cost");
		iCost.setFont(new Font("Arial", Font.PLAIN, 25));
		menu.add(iCost, gbc);
		JTextField cost = new JTextField(10);
		gbc.gridx = 1;
		gbc.gridy = 1;
		cost.setText(a.get(1));
		cost.setFont(new Font("Arial", Font.PLAIN, 25));
		menu.add(cost, gbc);

		//Third field of Active
		gbc.gridx = 2;
		gbc.gridy = 0;
		menu.add(new JLabel("Active?"), gbc);
		String[] activeYN = {"Yes", "No"};
		JComboBox active = new JComboBox(activeYN);
		active.setFont(new Font("Arial", Font.PLAIN, 25));
		//If an error was made on input, display what was previously selected
		if(a.get(0) != null){
			for(int i = 0; i < activeYN.length; i++){
				if (a.get(2).equals(activeYN[i].toString())){
					active.setSelectedIndex(i);
				}
			}
		}
		else{
			active.setSelectedIndex(0); //otherwise display the first option
		}
		active.setBackground(Color.WHITE);
		gbc.gridx = 2;
		gbc.gridy = 1;
		menu.add(active, gbc);

		//fourth field of Food/Drink
		gbc.gridx = 3;
		gbc.gridy = 0;
		menu.add(new JLabel("Food/Drink"), gbc);
		String[] type = {"Food", "Drink"};
		JComboBox foodDrink = new JComboBox(type);
		foodDrink.setFont(new Font("Arial", Font.PLAIN, 25));
		//If an error was made on input, display what was previously selected
		if(a.get(0) != null){
			for(int i = 0; i < type.length; i++){
				if (a.get(3).equals(type[i].toString())){
					foodDrink.setSelectedIndex(i);
				}
			}
		}
		else{
			foodDrink.setSelectedIndex(0); //otherwise display the first option
		}
		foodDrink.setBackground(Color.WHITE);
		gbc.gridx = 3;
		gbc.gridy = 1;
		menu.add(foodDrink, gbc);
		
		// fifth field of Specific Cat
		gbc.gridx = 4;
		gbc.gridy = 0;
		menu.add(new JLabel("Specific Category"), gbc);
		String[] specificCats = {"Appetizers", "Entrees", "Drinks", "Burgers", "Desserts"};		
		JComboBox specificCat = new JComboBox(specificCats);
		specificCat.setFont(new Font("Arial", Font.PLAIN, 25));
		// If an error was made on input, display what was previously selected
		if (a.get(0) != null) {
			for (int i = 0; i < specificCats.length; i++) {
				if (a.get(3).equals(specificCats[i].toString())) {
					specificCat.setSelectedIndex(i);
				}
			}
		} else {
			specificCat.setSelectedIndex(0); // otherwise display the first
												// option
		}
		specificCat.setBackground(Color.WHITE);
		gbc.gridx = 4;
		gbc.gridy = 1;
		menu.add(specificCat, gbc);

		//Clear 'a' arraylist if it contained data
		a.clear();
		
		font();
		
		

		int i = JOptionPane.showOptionDialog(
				null,
				menu,
				null,
				JOptionPane.YES_NO_OPTION,
				JOptionPane.PLAIN_MESSAGE,
				null,
				choices,
				defaultChoice);

		//Place the results from the inputs into an arraylist
		ArrayList<String> results = new ArrayList<String>();
		results.add(name.getText());
		results.add(cost.getText());
		results.add(active.getSelectedItem().toString());
		results.add(foodDrink.getSelectedItem().toString());
		results.add(specificCat.getSelectedItem().toString());
		
		//Parse results is submit is selected otherwise clear and cancel
		if (i==0){
			String price = parseManageMenu(results);

			if(price.equals("-1")){
				results.add("ERROR");
				return results;
			}
			else{
				results.set(1, price);
				return results;
			}
		}
		else {
			results.clear();
			return null;
		}
	}//End runMenuItem method

	/**
	 * Parses the input taken from the ManageEmployee fields
	 * @param data - the arraylist of the date from the runManageEmployee method
	 * @return - boolean of whether the data parses or not
	 */
	private static String parseManageMenu(ArrayList<String> data){

		String price = parseDollar(data.get(1));

		if(price.equals("-1")){
			font();
			JOptionPane.showMessageDialog(null, "$"+data.get(1) + " is an invalid amount.", null, JOptionPane.PLAIN_MESSAGE, null); 
			return "-1";
		}
		else{
			return price;
		}
	}//End of parseManageEmployee method

	/**
	 * Increases the size of the font for the JOptionPane buttons and displayed text
	 */
	private static void font(){
		//Increase size of the buttons
		UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("ARIAL",Font.PLAIN,40))); 
		//Increase size of the textfont
		UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("ARIAL",Font.PLAIN,40)));
		UIManager.put("OptionPane.inputFont", new FontUIResource(new Font("ARIAL",Font.PLAIN,40)));
	}//End font method


	public static String hostessTable(Integer tableNum) {
		font();
		int choice = JOptionPane.showOptionDialog(null, "Sit or Clean?",
				"Choose an option", JOptionPane.YES_NO_OPTION, 2, null,
				new String[] { "Sit", "Clean", "Reserve" }, "Sit");

		if (choice == 0) {
			Date time = new Date();
			DateFormat dateFormat = new SimpleDateFormat("HH:mm");
			String answer = tableNum.toString() + "-" + dateFormat.format(time);
			return answer;
		} 
		if(choice==2){
			return reservationTime(tableNum.toString());
		}
		else {
			return tableNum.toString();
		}
		
	}

	private static String reservationTime(String string) {
		font();
//		JLabel temp=new JLabel("");
//		temp.setFont(new Font("Arial",Font.BOLD,40));
		String time= JOptionPane.showInputDialog("What time is the reservation? (HH:MM)");
		if(time!=null)
			return ("RES-"+time);
		else
			return string;
	}

	public static boolean takeTable() {
		font();
		int choice = JOptionPane.showOptionDialog(null,
				"This is not in your section."
						+ "\n Do you want to add this table to your section?",
				"Choose an option", JOptionPane.YES_NO_OPTION, 2, null,
				new String[] { "Yes", "No" }, "No");
		if (choice == 0) {
			return true;
		}
		return false;
	}
}